/* Copyright 2007 Gearbox Software - http://www.gearboxsoft.com
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http:www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.*/


namespace GearBlog.Web.Controllers {
	using Castle.Components.Validator;
	using Castle.MonoRail.ActiveRecordSupport;
	using Castle.MonoRail.Framework;
	using Castle.Windsor;
	using Castle.Windsor.Configuration.Interpreters;
	using GearBlog.Web.Helpers;
	using GearBlog.Web.Models;

	/// <summary>
/// Summary description for ExtendedControllerBase
/// </summary>
	[Helper(typeof(StringHelper))]
	[Helper(typeof(DateHelper))]
	[Helper(typeof(ETextHelper), "EText")]
	[Helper(typeof(SecurityHelper))]
	[Helper(typeof(LayoutHelper))]
	[Helper(typeof(TrackBackHelper))]
	[Helper(typeof(IncludeHelper),"Include")]
	[Helper(typeof(PathHelper),"Path")]
	[Helper(typeof(FCKEditHelper),"FCKedit")]
	[Rescue("general")]
	public class ExtendedControllerBase : ARSmartDispatcherController
	{
		private Setting _setting;
		protected bool IsValid(object instance, out ValidatorRunner runner)
		{
			return IsValid(instance, out runner, RunWhen.Everytime);
		}
		protected bool IsValid(object instance, out ValidatorRunner runner, RunWhen runWhen)
		{
			runner = new ValidatorRunner((IValidatorRegistry)ServiceProvider.GetService(typeof(IValidatorRegistry)));
			return runner.IsValid(instance, runWhen);
		}
		internal Setting Setting
		{
			get
			{
				if (_setting == null) _setting = Setting.FindOne();
				return _setting;
			}
		}
		protected User CurrentUser
		{
			get
			{
				return (User) Context.CurrentUser;
			}
		}
		protected IWindsorContainer ServiceContainer
		{
			get
			{
				return new WindsorContainer(new XmlInterpreter());
			}
		}

	}
}
